/*
 * Copyright (c) Shenzhen 7th Road Technical Co., Ltd
 * Technical Support dept.
 * http://www.7road.com
 */
package com.sz7thrd.ts.ccu.filter.codec;

import java.nio.charset.Charset;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.textline.LineDelimiter;

/**
 * @author able
 * @date 2011-12-14
 * ===============================
 * 
 * 
 */
public class MyCodecFactory implements ProtocolCodecFactory {

    private final MyEncoder encoder;
    private final MyDecoder decoder;

    public MyCodecFactory() {
        this(Charset.defaultCharset());
    }

    public MyCodecFactory(Charset charset) {
        encoder = new MyEncoder(charset, LineDelimiter.UNIX);
        decoder = new MyDecoder(charset, LineDelimiter.AUTO);
    }

    public MyCodecFactory(Charset charset,
            String encodingDelimiter, String decodingDelimiter) {
        encoder = new MyEncoder(charset, encodingDelimiter);
        decoder = new MyDecoder(charset, decodingDelimiter);
    }

    public MyCodecFactory(Charset charset,
            LineDelimiter encodingDelimiter, LineDelimiter decodingDelimiter) {
        encoder = new MyEncoder(charset, encodingDelimiter);
        decoder = new MyDecoder(charset, decodingDelimiter);
    }

    public ProtocolEncoder getEncoder(IoSession session) {
        return encoder;
    }

    public ProtocolDecoder getDecoder(IoSession session) {
        return decoder;
    }

    public int getEncoderMaxLineLength() {
        return encoder.getMaxLineLength();
    }

    public void setEncoderMaxLineLength(int maxLineLength) {
        encoder.setMaxLineLength(maxLineLength);
    }

    public int getDecoderMaxLineLength() {
        return decoder.getMaxLineLength();
    }

    public void setDecoderMaxLineLength(int maxLineLength) {
        decoder.setMaxLineLength(maxLineLength);
    }
}